<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta charset="utf-8">
<title>查询两地间的距离</title>
<script type="text/javascript"
	src="http://ditu.google.cn/maps?file=api&amp;v=2&amp;key=ABQIAAAAMrMsJOafJ9iQiv3u_76UbBQm4AUyC40Ir8wQZ0YYDtq-7u5jTxR_huNC4jPVyeWLiqFB6w7bSuaPNw&sensor=true"></script>
<script type="text/javascript">
	var directions;
	function initialize() {
		directions = new GDirections(); //此类用于获取行车路线的结果，并将它显示在地图上和/或文本面板中   
		GEvent.addListener(directions, "load", onGDirectionsLoad);
		var str = "from: " + document.getElementById('ec').value + " to: "
				+ document.getElementById('sc').value;
		directions.load(str);
	}
	function onGDirectionsLoad() {
		if (directions.getStatus().code == G_GEO_SUCCESS) {
			var distance = document.getElementById('distance');
			distance.innerHTML = '两地的距离: ' + directions.getDistance().html; //getDistance()返回两个值，一个是称为“meters”的数字，表示距离的数值（以米为单位）；一个是称为“html”的字符串，包含本地化，如公里   
		}
	}
</script>

</head>
<body onunload="GUnload()">
	<b>查询两个城市间的距离：</b>
	<br /> 出发城市:&nbsp;
	<input type="text" id="sc" />
	<br /> 到达城市:&nbsp;
	<input type="text" id="ec" />
	<br />
	<input type="button" value="查询" id="bt" onclick="initialize()" />
	<div id="distance"></div>

</body>
</html>